(function(){"use strict";BX.namespace("BX.Landing.UI.Field");var i=BX.Landing.Utils.addClass;var t=BX.Landing.Utils.isArray;var e=BX.Landing.Utils.isPlainObject;var n=BX.Landing.Utils.isFunction;var a=BX.Landing.Utils.create;var l=BX.Landing.Utils.random;var s=BX.Landing.Utils.escapeHtml;var r=BX.Landing.Utils.append;var c=BX.Landing.Utils.slice;var u=BX.Landing.Utils.encodeDataValue;var d=BX.Landing.Utils.decodeDataValue;var h=BX.Landing.Utils.isNumber;var o=BX.Landing.Utils.isBoolean;var p=BX.Landing.Utils.data;var f=BX.Landing.Utils.clone;BX.Landing.UI.Field.Checkbox=function(e){BX.Landing.UI.Field.BaseField.apply(this,arguments);i(this.layout,"landing-ui-field-checkbox");this.onChangeHandler=n(e.onChange)?e.onChange:function(){};this.items=t(e.items)?e.items:[];this.value=t(e.value)?e.value:null;this.depth=h(e.depth)?e.depth:0;this.compact=o(e.compact)?e.compact:false;this.multiple=e.multiple!==false;p(this.layout,"data-depth",this.depth);p(this.layout,"data-compact",this.compact);if(t(this.value)){this.value=this.value.map(function(i){return d(i)})}if(!t(this.value)){this.value=this.items.filter(function(i){return i.checked}).map(function(i){return d(i.value)})}this.content=this.value;this.items.forEach(this.addItem,this)};BX.Landing.UI.Field.Checkbox.prototype={constructor:BX.Landing.UI.Field.Checkbox,__proto__:BX.Landing.UI.Field.BaseField.prototype,addItem:function(i){if(e(i)){var t="checkbox_item_"+l();var n=a("div",{props:{className:"landing-ui-field-checkbox-item"+(i.disabled?" landing-ui-disabled":"")},children:[a("input",{props:{className:"landing-ui-field-checkbox-item-checkbox"},attrs:{id:t,type:"checkbox",value:u(i.value),checked:this.value.find(function(t){return t==i.value})!==undefined},events:{change:this.onItemChange.bind(this)}}),a("label",{props:{className:"landing-ui-field-checkbox-item-label"},attrs:{for:t,title:BX.Text.encode(i.name)},html:i.html?i.html:s(i.name)})]});r(n,this.input)}return n},onItemChange:function(){this.onChangeHandler(this);this.onValueChangeHandler(this);this.emit("onChange")},isChanged:function(){var i=f(this.content).sort();var t=this.getValue().sort();return JSON.stringify(i)!==JSON.stringify(t)},setValue:function(i){if(t(i)){c(this.input.children).forEach(function(i){i.querySelector("input").checked=false});i.forEach(function(i){var t=c(this.input.children).find(function(t){return d(t.querySelector("input").value)==i},this);if(t){t.querySelector("input").checked=true}},this)}},getValue:function(){var i=c(this.input.children).filter(function(i){return i.querySelector("input").checked}).map(function(i){return d(i.querySelector("input").value)});if(!this.multiple){return i.length>0?i[0]:false}return i}}})();
//# sourceMappingURL=checkbox_field.map.js